package com.openvas.controller;

import java.util.List;
//    import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.openvas.commons.common.annotation.Log;
import com.openvas.commons.common.enums.BusinessType;
import com.openvas.domain.TableReport;
import com.openvas.service.ITableReportService;
import com.openvas.commons.common.core.controller.BaseController;
import com.openvas.commons.common.core.domain.AjaxResult;

import com.openvas.commons.common.core.page.TableDataInfo;

/**
 * 报告Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/api/report")
public class TableReportController extends BaseController
{
    private String prefix = "system/report";

    @Autowired
    private ITableReportService tableReportService;

   // //  @RequiresPermissions("system:report:view")
    @GetMapping()
    public String report()
    {
        return prefix + "/report";
    }

    /**
     * 查询报告列表
     */
   // //  @RequiresPermissions("system:report:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableReport tableReport)
    {
        startPage();
        List<TableReport> list = tableReportService.selectTableReportList(tableReport);
        return getDataTable(list);
    }

    /**
     * 导出报告列表
     */
   // //  @RequiresPermissions("system:report:export")
    @Log(title = "报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableReport tableReport)
    {
        List<TableReport> list = tableReportService.selectTableReportList(tableReport);
//        ExcelUtil<TableReport> util = new ExcelUtil<TableReport>(TableReport.class);
//        return util.exportExcel(list, "报告数据");
        return null;
    }

    /**
     * 新增报告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报告
     */
   // //  @RequiresPermissions("system:report:add")
    @Log(title = "报告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableReport tableReport)
    {
        return toAjax(tableReportService.insertTableReport(tableReport));
    }

    /**
     * 修改报告
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TableReport tableReport = tableReportService.selectTableReportById(id);
        mmap.put("tableReport", tableReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存报告
     */
   // //  @RequiresPermissions("system:report:edit")
    @Log(title = "报告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableReport tableReport)
    {
        return toAjax(tableReportService.updateTableReport(tableReport));
    }

    /**
     * 删除报告
     */
   // //  @RequiresPermissions("system:report:remove")
    @Log(title = "报告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableReportService.deleteTableReportByIds(ids));
    }
}
